use std::sync::OnceLock;

use bytes::Bytes;
use serde::Deserialize;
use tools::global_defin::config::load_config;

///sip的配置文件相关
#[derive(Debug, Deserialize)]
pub struct SdpConfig {
	pub rtp_audio_attribs: Vec<u8>,
	#[serde(default = "default_session_name")]
	pub sdp_sission_name: &'static str,
}

pub fn default_session_name() -> &'static str {
	"-"
}

/**
 * sdp的配置文件
 */
#[inline]
pub fn sdp_config() -> &'static SdpConfig {
	static CONFIG: OnceLock<SdpConfig> = OnceLock::new();
	// 尝试获取或初始化配置信息
	CONFIG.get_or_init(|| load_config("./config/sdp.json"))
}

pub(crate) fn get_session_name_bytes() -> &'static Bytes {
	static CONFIG: OnceLock<Bytes> = OnceLock::new();
	// 尝试获取或初始化配置信息
	CONFIG.get_or_init(|| Bytes::copy_from_slice(sdp_config().sdp_sission_name.as_bytes()))
}
